package top.kaoshanji.p2ch09a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * 代码清单-p2ch09a-288页a：ClassLoader类的loadClass方法的使用示例
 * author kaoshanji
 * ^_^
 * create time 2025/1/24 18:50
 */
public class SimpleClassLoaderUsage {

    private static final Logger logger = LogManager.getLogger(SimpleClassLoaderUsage.class);

    public static void main(String[] args) throws Exception {
        logger.info("...代码清单-p2ch09a-288页a：ClassLoader类的loadClass方法的使用示例...");

        SimpleClassLoaderUsage example = new SimpleClassLoaderUsage();
        example.loadClass();

    }

    public void loadClass() throws Exception {
        ClassLoader current = getClass().getClassLoader();
        Class<?> clazz = current.loadClass("java.lang.String");
        Object str = clazz.newInstance();

        logger.info("...String的名称：{}...", str.getClass());

    }

}
